package com.service.controller;

import com.service.pojo.User;
import com.service.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class UserController {

    @Autowired
    private IUserService userService;

    @RequestMapping("/findUserAll")
    public List<User> findAllUser(){
       /* try {
            // 熔断测试 逻辑
            Thread.sleep(7000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }*/
        return this.userService.findAllUser();
    }

    @RequestMapping("/findOneUser/{id}")
    public User findOneUser(@PathVariable("id") Integer id){
        return this.userService.findOneUser(id);
    }

    @RequestMapping("/findUserById/{id}")
    public Map findUserById(@PathVariable("id") Integer id){
        Map map = new HashMap();
        map.put("msg","成功");
        map.put("code",0);
        map.put("data",this.userService.findOneUser(id));
        return map;
    }
}
